/**
 * Created by Administrator on 2017/6/12.
 */
var mongoose = require('mongoose');
var config = require('../../config.json');
var dbUrl = config.dbUrl;

/**
 * 连接
 */
mongoose.Promise = global.Promise;
mongoose.connect(dbUrl,{useMongoClient:true});

/**
 * 连接成功
 */
mongoose.connection.on('connected', function () {
  console.log('Mongoose connection open to ' + dbUrl);
});

/**
 * 连接异常
 */
mongoose.connection.on('error',function (err) {
  console.log('Mongoose connection error: ' + err);
});

/**
 * 连接断开
 */
mongoose.connection.on('disconnected', function () {
  console.log('Mongoose connection disconnected');
});

module.exports = mongoose;